FROM java:8

# 设置工作目录
WORKDIR /app

# 设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 复制构建产物
COPY ./target/smarthome.jar ./app.jar

# 暴露端口
EXPOSE 9090

# 设置启动命令
ENTRYPOINT ["java", \
    # JVM 内存设置
    "-Xms512m", \
    "-Xmx512m", \
    # 元空间大小设置
    "-XX:MetaspaceSize=128m", \
    "-XX:MaxMetaspaceSize=256m", \
    # GC 设置
    "-XX:+UseG1GC", \
    "-XX:MaxGCPauseMillis=200", \
    # GC 日志设置
    "-XX:+PrintGCDetails", \
    "-XX:+PrintGCDateStamps", \
    "-Xloggc:/app/logs/gc.log", \
    # 内存溢出时dump
    "-XX:+HeapDumpOnOutOfMemoryError", \
    "-XX:HeapDumpPath=/app/logs/heap-dump.hprof", \
    # 启动 jar
    "-jar", "/app/app.jar"]

# 设置默认启动参数
CMD ["--spring.profiles.active=prod"]
